import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select

testCase = "DBshop003货到付款流程"

firefox = openBrowser(url)
DBshopLogin(firefox,userName,password)
firefox.find_element_by_xpath("//input[@placeholder='简简单单搜索']").send_keys("小米")
firefox.find_element_by_xpath("//input[@class='search-btn iconfont']").click()
firefox.find_element_by_xpath("//a[@href='/dbshop/goods/8/2']").click()
switchWindow(firefox,2)
firefox.find_element_by_id("add_cart_submit").click()
firefox.find_element_by_link_text("去购物车结算").click()
firefox.find_element_by_link_text("去结算").click()
firefox.find_element_by_xpath("//input[@value='下一步']").click()
firefox.find_element_by_xpath("//input[@value='hdfk']").click()
time.sleep(3)
firefox.find_element_by_xpath("//input[@class='btn btn-large btn-primary']").click()
orderNO=firefox.find_element_by_xpath('(//font[@color="color:#ED145B"])[2]').text
rootPath=get_pro_rootpath()
writeFile(rootPath+'\public\order3.txt',orderNO) # 将订单编号写入到文件中
# 6.点击马上支付,输入"支付凭证信息","线下支付宝支付",点击提交支付凭证按钮
# firefox.find_element_by_xpath('//input[@value="马上去支付"]').click()

# 登录后台管理系统
firefox.get(urlAdmin)
#调用自定义函数进行后台的登录
DBshopLoginAdmin(firefox)
DBshopEnterMenu2(firefox,"销售管理","订单管理")
firefox.find_element_by_name('order_sn').send_keys(orderNO)
firefox.find_element_by_xpath("//button[@class='btn btn-small btn-primary']").click()
firefox.find_element_by_link_text("编辑查看").click()
firefox.find_element_by_link_text("发货操作").click()
firefox.find_element_by_xpath("//button").click()
firefox.find_element_by_link_text("付款操作").click()
K = firefox.find_element_by_id("pay_state")
ActionChains(firefox).move_to_element(K).perform()
Select(K).select_by_visible_text("已付款")

firefox.find_element_by_xpath("//button").click()




# 登录前台
firefox.get(url)
firefox.find_element_by_link_text("我的订单").click()
firefox.find_element_by_partial_link_text("已发货").click()
firefox.find_element_by_name('search_order_sn').send_keys(orderNO)
firefox.find_element_by_xpath('//button').click()
#点击确认收货
firefox.find_element_by_xpath('//button[text()="确认收货"]').click()
firefox.find_element_by_xpath('//button[@type="submit"]').click()
firefox.switch_to.alert.accept()
# 12.到dbshop前台查看我的订单"交易完成"中,检查上面的订单状态
#点击交易完成
firefox.find_element_by_partial_link_text('交易完成').click()
firefox.find_element_by_name('search_order_sn').send_keys(orderNO)
firefox.find_element_by_xpath('//button').click()
#断言
try:
    firefox.find_element_by_link_text(orderNO).is_displayed()  #is_displayed()函数判断元素是否显示
    writeLog("%s 测试通过"%testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()